<!--党务办学习统计搜索-->
<template>
    <!-- --------党员答题统计---------------start -->
    <div id="organization" class="mui-control-content mui-active">
      <ul class="mui-table-view organization-lists">
        <li class="mui-table-view-cell" @click="go(item)" v-if="item.partyGroupName.indexOf(initKeywords)>=0" v-for="item in list">
          <div class="flex-between-center mine-lists-content">
            <h2 class="organization-lists-title" v-html="highLight(initKeywords,item.partyGroupName)">中国湖南省永州监狱<b class="work-red">财务科党支部</b></h2>
            <span class="mui-icon mui-icon-arrowright"></span>
          </div>
        </li>
      </ul>
      <noData v-if="!hasList() && !isLoading"></noData>
    </div>
    <!-- --------党员答题统计---------------end -->
</template>

<script>
  import tools from '@/utils/tools'
  import loginService from '@/service/loginService'
  import moment from 'moment'
  export default {
    name: 'studySearchAnswerComponent',
    props: {
      initKeywords: {
        type: String,
        default: ''
      }
    },
    data () {
      return {
        fn: tools,
        list: [],
        objectsName: '',
        refresh: 0,
        keywords: ''
      }
    },
    created () {
      this.loadData()
    },
    methods: {
      highLight (key, str) {
        let searchReg = new RegExp(`${key}`, 'g')
        let searchReplace = `<b class="work-red">${key}</b>`
        // 标红字体
        if (key.length > 0) {
          return str.replace(searchReg, searchReplace)
        }
        return str
      },
      hasList () {
        if (this.list && this.list.length > 0) {
          return true
        }
        return false
      },
      loadData () {
        let roleType = this.$localStorage.get('roleType')
        let yearMonth = moment(this._time).format('YYYY-MM')
        let data
        if (this.fn.hasDwbRoleType(roleType)) {
          data = {
            yearMonth: yearMonth
          }
        } else {
          let userInfo = this.$store.state.userInfo
          let partyGroupId = userInfo.partyMemberModel.partyGroupId
          let partyGroupName = userInfo.partyMemberModel.partyGroupName
          data = {
            id: partyGroupId,
            partyGroupName: partyGroupName,
            yearMonth: yearMonth
          }
        }
        this.isLoading = true
        loginService.getPartyGroupAnswerByMonth(data).then(res => {
          this.isLoading = false
          if (res.code !== 200) {
            return tools.tip(res.message)
          }
          this.list = res.data
          this.list.map(v => {
            let yearMonths = yearMonth.split("-")
            v.year = yearMonths[0]
            v.month = yearMonths[1]
          })
        })
      },
      reloadData () {
        this.loadData()
      },
      go (item) {
        // 保存此条信息
        this.$store.state.studySituationItem = item
        this.$router.push({path: '/studyAnswerSituation'})
      }
    },
    watch: {
      initKeywords (newValue, oldValue) {
        this.keywords = newValue
      }
    }
  }
</script>

<style scoped lang="scss">
  .screen-btn {
    /*margin-bottom: 80px;*/
  }
  .aside-menu.mui-off-canvas-right {
    z-index:999;
    visibility:visible;
  }
</style>
